package com.example.demo.controller;

import com.example.demo.common.ResultAjax;
import com.example.demo.model.Userinfo;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/reg")
    public ResultAjax reg(Userinfo userinfo) {
       // 1.校验参数
        if (userinfo == null || !StringUtils.hasLength(userinfo.getUsername()) ||
        !StringUtils.hasLength(userinfo.getPassword())) {
            return ResultAjax.fail(-1,"异常");
        }
        // 2.请求接口 service 进行添加接口
        int ret = userService.reg(userinfo);
        // 3.将结果返回给前端
        return ResultAjax.success(ret);
    }

}
